class_name HurtComponent
extends Node2D

@export var hurt_duration := 0.5
@export var health = 3

@onready var player_state:StateComponent = get_parent().get_node("PlayerState")
@onready var plater_sprite:CharacterBody2D = get_parent()

func _ready():
	EventBus.emit_signal("player_heath", health)
	EventBus.connect("player_hurt", hurt)

func handle_hurt_recovery():
	if player_state.get_current_state() == PlayerEnums.AnimState.HURT && plater_sprite.is_on_floor():
		await get_tree().create_timer(hurt_duration).timeout
		player_state.transition_to(PlayerEnums.AnimState.IDLE)

func handle_hurt():
	handle_hurt_recovery()

func hurt(direction: int):
	health -= 1
	player_state.transition_to(PlayerEnums.AnimState.HURT)
	EventBus.emit_signal("player_heath", health)
	